package com.ruoyi.project.business.salarydetail.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.project.business.salarydetail.entity.SalaryDetail;
import com.ruoyi.project.business.salarydetail.mapper.SalaryDetailMapper;
import com.ruoyi.project.business.salarydetail.request.AddSalaryDetailRequest;
import com.ruoyi.project.business.salarydetail.request.ListSalaryDetailRequest;
import com.ruoyi.project.business.salarydetail.response.SalaryDetailResponse;
import com.ruoyi.project.business.salarydetail.service.ISalaryDetailService;
import com.ruoyi.project.business.utils.BusinessUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 薪资明细Service业务层处理
 * 
 * @author ${author}
 * @date 2024-03-20
 */
@Service
public class SalaryDetailServiceImpl implements ISalaryDetailService {
    @Autowired
    private SalaryDetailMapper salaryDetailMapper;

    /**
     * 查询薪资明细
     * 
     * @return 薪资明细
     */
    @Override
    public SalaryDetail selectSalaryDetailById(Long id) {
        return salaryDetailMapper.selectSalaryDetailById(id);
    }

    /**
     * 查询薪资明细列表
     * 
     * @return 薪资明细
     */
    @Override
    public List<SalaryDetailResponse> selectSalaryDetailList(ListSalaryDetailRequest request, Long tenantId) {
        // TODO request to  param
        SalaryDetail param = BeanUtils.copy(request, SalaryDetail.class);
        param.setTenantId(tenantId);
        List<SalaryDetail> entitis = salaryDetailMapper.selectSalaryDetailList(param);
        List<SalaryDetailResponse> resList = BeanUtils.copyList(entitis, SalaryDetailResponse.class);
        BusinessUtil.fillListNames(resList, tenantId);
        return resList;
    }

    /**
     * 新增薪资明细
     * 
     * @return 结果
     */
    @Override
    public int insertSalaryDetail(AddSalaryDetailRequest request, Long operatorId, Long tenantId) {
        SalaryDetail entity = BeanUtils.copy(request, SalaryDetail.class);
        entity.setTenantId(tenantId);
        entity.setCreator(operatorId);
        entity.setDeleted(Boolean.FALSE);
        entity.setCreateTime(DateUtils.getNowDate());
        return salaryDetailMapper.insertSalaryDetail(entity);
    }

    /**
     * 修改薪资明细
     * 
     * @return 结果
     */
    @Override
    public int updateSalaryDetail(SalaryDetail entity, Long operatorId, Long tenantId) {
        entity.setUpdateTime(DateUtils.getNowDate());
        entity.setTenantId(tenantId);
        entity.setUpdater(operatorId);
        return salaryDetailMapper.updateSalaryDetail(entity);
    }

    /**
     * 批量删除薪资明细
     * 
     * @return 结果
     */
    @Override
    public int deleteSalaryDetailByIds(Long[] ids, Long operatorId, Long tenantId) {
        return salaryDetailMapper.deleteSalaryDetailByIds(ids);
    }

    /**
     * 删除薪资明细信息
     * 
     * @return 结果
     */
    @Override
    public int deleteSalaryDetailById(Long id, Long operatorId, Long tenantId) {
        return salaryDetailMapper.deleteSalaryDetailById(id);
    }

    @Override
    public void deleteMonthSalaryDetailByMonthSalaryId(Long monthSalaryId, Long operatorId, Long tenantId) {
        salaryDetailMapper.deleteMonthSalaryDetailByMonthSalaryId(monthSalaryId, tenantId);
    }
}
